$('#table').bootstrapTable({
    url: '/myOrders',
    method: 'post',
    pagination: 'true',
    columns: [{
        field: 'id',
        title: 'ID',
        visible: false
    }, {
        field: 'nickname',
        title: '昵称',
        visible: false
    }, {
        field: 'addr',
        title: '地址',
        formatter: addrFormatter,
        visible: false
    }, {
        field: 'title',
        'title': '商品名称',
        formatter: titleFormatter,
    }, {
        field: 'quantity',
        title: '数量',
        sortable: 'true'
    }, {
        field: 'now_price',
        title: '单价(元)',
        sortable: 'true',
        visible: false
    }, {
        field: 'created_at',
        title: '购买时间',
        sortable: 'true'
    }, {
        field: 'status',
        title: '状态',
        formatter: statusFormatter,
        sortable: 'true'
    }, {
        field: 'express_company',
        title: '快递公司',
        visible: false
    }, {
        field: 'express_no',
        title: '快递单号',
        visible: false
    }]
});

function addrFormatter(value, row, index){
    return row['country']+' ' + row['province']+' '+row['city'];
}

function titleFormatter(value, row, index){
    if (row['status'] == 3 ){
        quantity = row['quantity'];
        task_id = row['task_id'];
        roid = row['id'];
        return '<a href="/addr?id='+row['item_id']+'&quantity='+quantity+'&task_id='+task_id+'&roid='+roid+'">'+row['title']+'</a>';
    }
    else {
        return '<a href="/item/pay?id='+row['item_id']+'">'+row['title']+'</a>';
    }

}

function statusFormatter(value, row, index){
    if (value == 1){
        return '待发货';
    }
    else if(value == 2){
        return '已发货';
    }
    else if(value == 3){
        return '待支付';
    }
    else if(value == 4){
        return '已超时';
    }
}
